package com.itheima.project.handler.wechat.client;

import com.itheima.project.exception.ProjectException;
import com.itheima.project.handler.wechat.operators.baisc.Query;
import com.itheima.project.handler.wechat.operators.baisc.Refund;
import com.itheima.project.handler.wechat.operators.natives.NativePreCreate;
import com.itheima.project.handler.wechat.operators.jspai.JsapiPreCreate;
import com.itheima.project.handler.wechat.response.JsapiPreCreateResponse;
import com.itheima.project.handler.wechat.response.NativePreCreateResponse;
import com.itheima.project.handler.wechat.response.QueryResponse;
import com.itheima.project.handler.wechat.response.RefundResponse;
import lombok.Data;
import lombok.extern.log4j.Log4j2;

/**
 * @ClassName Factory.java
 * @Description 封装对于微信支付工程类
 */
@Data
@Log4j2
public class Factory {

    static Query basicQuery;

    static JsapiPreCreate jsapiPreCreate;

    static NativePreCreate nativePreCreate;

    static Refund refund;

    public static void setOptions(Config config){
        basicQuery = new Query(config);
        jsapiPreCreate = new JsapiPreCreate(config);
        nativePreCreate = new NativePreCreate(config);
        refund = new Refund(config);
    }


    /***
     * @description Jsapi统一收单线下交易预创建
     *
     * @param outTradeNo  外部订单【业务系统中间的交易单号】
     * @param amount    交易的金额【单位：分】
     * @param description   商品的描述
     * @param openId    用户在当前公众号下的OpenID
     * @return: com.itheima.restkeeper.handler.wechat.response.JsapiPreCreateResponse
     */
    public static JsapiPreCreateResponse jsapiPreCreate(String outTradeNo, String amount, String description, String openId){
        return jsapiPreCreate.jsapiPreCreate( outTradeNo,  amount,  description, openId);
    }

    /***
     * @description 统一收单线下交易预创建
     * @param outTradeNo 发起支付传递的交易单号
     * @param amount 交易金额【元】
     * @param description 商品描述
     * @return
     */
    public static NativePreCreateResponse nativepreCreate(String outTradeNo, String amount,
                                                    String description) throws ProjectException {
        return nativePreCreate.nativePreCreate( outTradeNo,  amount,  description);
    }

    /***
     * @description 统一收单线下交易查询
     * @param outTradeNo 发起支付传递的交易单号
     * @return
     */
    public static QueryResponse query(String outTradeNo){
        return basicQuery.query(outTradeNo);
    }


    /***
     * @description 统一收单交易退款接口
     * @param outTradeNo 发起支付传递的交易单号
     * @param amount 退款金额
     * @param outRefundNo 商户系统内部的退款单号，商户系统内部唯一，只能是数字、大小写字母_-|*@ ，同一退款单号多次请求只退一笔
     * @param total 原订单金额
     * @return
     */
    public static RefundResponse refund(String outTradeNo, String amount,
                                              String outRefundNo, String total) throws ProjectException{
        return refund.refund( outTradeNo,  amount,
                 outRefundNo,  total);
    }

    /***
     * @description 统一收单交易退款接口查询
     * @param outRefundNo 商户系统内部的退款单号
     * @return
     */
    public static RefundResponse queryRefund(String outRefundNo){
        return basicQuery.queryRefund(outRefundNo);
    }

}
